package com.sos.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 映射文件访问路径到实际文件存储路径
        registry.addResourceHandler("/files/**")
                .addResourceLocations("file:./uploads/")
                .setCachePeriod(3600);
                
        // 由于context-path是/api，所以还需要映射/api/files/**
        registry.addResourceHandler("/api/files/**")
                .addResourceLocations("file:./uploads/")
                .setCachePeriod(3600);
    }
}